/**
 * 0021
 *  
 * @Author : Ruoyu Wang
 * @DateTime : 24-11-11 下午5:24
 */

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct ListNode {
    int val;
    ListNode *next;

    ListNode() : val(0), next(nullptr) {}

    ListNode(int x) : val(x), next(nullptr) {}

    ListNode(int x, ListNode *next) : val(x), next(next) {}
};


class Solution {
public:
    ListNode *mergeTwoLists(ListNode *list1, ListNode *list2) {
        ListNode *h = new ListNode(-1);
        ListNode *p = h;
        while (list1 != nullptr && list2 != nullptr) {
            if (list1->val <= list2->val) {
                p->next = list1;
                list1 = list1->next;
            } else {
                p->next = list2;
                list2 = list2->next;
            }
            p = p->next;
            p->next = nullptr;
        }
        while (list1 != nullptr) {
            p->next = list1;
            list1 = list1->next;
            p = p->next;
            p->next = nullptr;
        }
        while (list2 != nullptr) {
            p->next = list2;
            list2 = list2->next;
            p = p->next;
            p->next = nullptr;
        }
        return h->next;
    }
};

int main() {

    return 0;
}